#include "graph.h"

void set_ygraph(graph_t* graph,uint8_t from,uint8_t to,uint8_t param) {
    graph->point = from;
    graph->point_val[to] = param;
    while (1) {
        graph->point_val[graph->point] = graph->point_val[graph->point + 1];
        ++graph->point;
        if (graph->point == to) break;
    }
}

void draw_ygraph(graph_t* graph,graphics_t* graphics,uint8_t from,uint8_t to) {
    graph->draw_point = from;
    while (1) {
        graphics_set_pixel(graphics, graph->draw_point, graph->point_val[graph->draw_point]);
        ++graph->draw_point;
        if (graph->draw_point == to) break;
    }
}

void init_ygraph(graph_t* graph,uint8_t param) {
    graph->point = 0;
    while (1) {
        graph->point_val[graph->point]=param;
        if (graph->point == 127) break;
        ++graph->point;
    }
}

void draw_xgraph_inverted(graph_t* graph,graphics_t* graphics,uint8_t from,uint8_t to,uint8_t param) {
    graph->point = from;
    graph->point_val[to] = param;
    while (1) {
        graph->point_val[graph->point] = graph->point_val[graph->point + 1];
        ++graph->point;
        if (graph->point == to) break;
    }
    graph->draw_point = from;
    while (1) {
        graphics_set_pixel(graphics,graph->point_val[graph->draw_point], graph->draw_point);
        ++graph->draw_point;
        if (graph->draw_point == to) break;
    }
}

void draw_xgraph(graph_t* graph, graphics_t* graphics, uint8_t from, uint8_t to, uint8_t param, uint8_t order,int8_t shift) {
    if (order==0) {
        graph->point = to;
        graph->point_val[from] = param;
        while (1) {
            graph->point_val[graph->point] = graph->point_val[graph->point - 1]+shift;
            --graph->point;
            if (graph->point == from) break;
        }
    }
    graph->draw_point = to;
    while (1) {
        graphics_set_pixel(graphics, graph->point_val[graph->draw_point], graph->draw_point);
        --graph->draw_point;
        if (graph->draw_point == from) break;
    }
}

void init_xgraph(graph_t* graph,uint8_t param) {
    graph->point = 0;
    while (1) {
        graph->point_val[graph->point]=param;
        if (graph->point == 127) break;
        ++graph->point;
    }
}
